import 'package:flutter/material.dart';
import '../models/ArticleModel.dart';
import 'package:metaera_flutter/utils/Device.dart';
import 'package:metaera_flutter/utils/Font.dart';
import 'package:metaera_flutter/utils/Color.dart';
import '../routes/Router.dart';
import 'package:metaera_flutter/utils/Tool.dart';

class ArticleItem extends StatelessWidget {
  final ArticleModel articleModel;
  final VoidCallback? onTap;
  const ArticleItem({super.key, required this.articleModel, this.onTap});

  // 同时修改 showDetailTap 方法签名并接收 context
  void showDetailTap(BuildContext context, ArticleModel model) {
    Navigator.pushNamed(
      context,
      AppRoutes.articleDetail,
      arguments: {'id': model.id},
    );
  }

  void shareTap(BuildContext context, ArticleModel model) {}

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: DeviceUtils.width18),
      child: InkWell(
        onTap: () => showDetailTap(context, articleModel),
        child: Padding(
          padding: EdgeInsets.only(
            top: DeviceUtils.width4,
            bottom: DeviceUtils.width8,
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 左侧的点和竖线
              IntrinsicHeight(
                child: Column(
                  children: [
                    // 时间点（小圆点）
                    Container(
                      width: DeviceUtils.width8,
                      height: DeviceUtils.width8,
                      decoration: BoxDecoration(
                        color: AppColors.color6184DD,
                        shape: BoxShape.circle,
                      ),
                    ),
                    // 上间距
                    SizedBox(height: DeviceUtils.width20),
                    // 竖线 - 使用 Expanded 填充剩余空间
                    Expanded(
                      child: Container(
                        width: DeviceUtils.width2,
                        color: AppColors.colorD8D8D8,
                      ),
                    ),
                    // 下间距
                    SizedBox(height: DeviceUtils.width20),
                  ],
                ),
              ),

              // 内容区域
              SizedBox(width: DeviceUtils.width12), // 左侧间距
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    // 时间显示（左上角）
                    Text(
                      AppTool.formatTime(
                        DateTime.parse(
                          articleModel.releaseTime ??
                              '2023-07-01T00:00:00.000Z',
                        ),
                      ),
                      style: TextStyle(
                        fontSize: AppFonts.fontSize12,
                        color: AppColors.color9C9C9C,
                      ),
                    ),

                    // 标题（大字号，加粗）
                    Padding(
                      padding: EdgeInsets.only(top: DeviceUtils.width8),
                      child: Text(
                        articleModel.title ?? '暂无标题',
                        style: TextStyle(
                          fontSize: AppFonts.fontSize16,
                          fontWeight: FontWeight.bold,
                          color: Colors.black,
                        ),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),

                    // 内容摘要（小字号，灰色）
                    Padding(
                      padding: EdgeInsets.only(top: DeviceUtils.width8),
                      child: Text(
                        articleModel.content ?? '',
                        style: TextStyle(
                          fontSize: AppFonts.fontSize14,
                          color: AppColors.color9C9C9C,
                        ),
                        maxLines: 3,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),

                    // 底部操作栏（分享和展开）
                    Padding(
                      padding: EdgeInsets.only(top: DeviceUtils.width12),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          // 分享按钮
                          GestureDetector(
                            onTap: () => shareTap(context, articleModel),
                            child: Row(
                              children: [
                                Image.asset(
                                  'assets/images/base/share.png',
                                  width: DeviceUtils.width16,
                                  height: DeviceUtils.width16,
                                ),
                                SizedBox(width: DeviceUtils.width8),
                                Text(
                                  '分享',
                                  style: TextStyle(
                                    fontSize: AppFonts.fontSize14,
                                    color: AppColors.color9C9C9C,
                                  ),
                                ),
                              ],
                            ),
                          ),

                          // 展开按钮
                          GestureDetector(
                            onTap: () => showDetailTap(context, articleModel),
                            child: Text(
                              '收起',
                              style: TextStyle(
                                fontSize: AppFonts.fontSize14,
                                color: AppColors.color9C9C9C,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
